/*
 * CcInitializer.c
 *
 *  Created on: 2012/04/28
 *      Author: guanxiaoying
 */
#include "../coredef.h"
#include "cc.h"

static AST ccInitializerBlock( VOID );
static AST ccInitializerList( VOID );

static AST ccInitializerAssignExp( U4  *usEndSym ){
	AST astExp;
	AST astInitial;
	AST firstScp;
	AST astCurrToken;

	astCurrToken = CcLexGetCurrToken( );
	firstScp = stLexTokenAccess.codeScp.get( astCurrToken );
	stExpressionListAccess.alloc(1);
	astInitial = stExpressionListAccess.getMax();

	astExp = CcExpression( usEndSym, KIND_INITIALEXPLIST, astInitial );
	if( astExp == 0 ){
		astCurrToken = CcLexGetCurrToken( );
		CcThrowWarning( CC_INITEXP_SYNTAX_ERROR,
				stLexTokenAccess.codeScp.get( astCurrToken ),
				stLexTokenAccess.name.get( astCurrToken ),NULL );
		stExpressionListAccess.bIllegal.set(astInitial, TRUE);
	}else{
		firstScp = stExpressionAccess.codeScp.get( astExp );
		stExpressionListAccess.constFlg.set( astInitial, stExpressionAccess.constFlg.get( astExp ));
	}
	stExpressionListAccess.codeScp.set( astInitial, firstScp );
	stExpressionListAccess.expression.set( astInitial, astExp );
	return astInitial;
}
static AST ccInitializerDesignation( VOID ){
	AST astDesignation=0;
	AST astPreDesignation=0;
//	AST astResult=0;
	U4  endToken[2]={ xLEX_CLOSEARRAY, xLEX_UNDEFINED};
	AST astExp;
	AST firstScp, secondScp;
	AST astCurrToken;
	U4  currTokenKind;

	astCurrToken = CcLexGetCurrToken( );
	currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );

	while( currTokenKind == xLEX_MEMREF || currTokenKind == xLEX_OPENARRAY ){
		firstScp = stLexTokenAccess.codeScp.get( astCurrToken );
		stInitDesignationAccess.alloc(1);
		astDesignation = stInitDesignationAccess.getMax();
		if( currTokenKind == xLEX_MEMREF ){

			astCurrToken = CcLexGetNextToken( );
			currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );
			if( currTokenKind == xLEX_SYMBOL ){
				stInitDesignationAccess.token.set( astDesignation, astCurrToken );
				astCurrToken = CcLexGetNextToken( );
			}else{
				CcThrowWarning( CC_INITEXP_SYNTAX_ERROR,
						stLexTokenAccess.codeScp.get( astCurrToken ),
						stLexTokenAccess.name.get( astCurrToken ),NULL );
				stInitDesignationAccess.bIllegal.set( astDesignation, TRUE );
			}
			stInitDesignationAccess.kind.set( astDesignation, DESIGNATION_TOKEN );
		}else{
			stInitDesignationAccess.kind.set( astDesignation, DESIGNATION_ARRAY );
			astCurrToken = CcLexGetNextToken( );
			astExp = CcConstantExpression( endToken, KIND_INITDESIGNATION, astDesignation );

			astCurrToken = CcLexGetCurrToken( );
			currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );

			if( astExp == 0 ){
				CcThrowWarning( CC_INITEXP_SYNTAX_ERROR,
						stLexTokenAccess.codeScp.get( astCurrToken ),
						stLexTokenAccess.name.get( astCurrToken ),NULL );
				stInitDesignationAccess.bIllegal.set( astDesignation, TRUE );
			}else{
				if( stExpressionAccess.constFlg.get( astExp ) != CONSTANT_VALUE ){
					CcThrowWarning( CC_INITEXP_DESIGNATION_NEED_CONST,
							stExpressionAccess.codeScp.get( astExp ),
							NULL,NULL );
					stInitDesignationAccess.bIllegal.set( astDesignation, TRUE );
				}else{
					AST astType = stExpressionAccess.castedType.get( astExp );
					if( !CcTypeIsInteger( astType )){
						CcThrowWarning( CC_INITEXP_DESIGNATION_NEED_INTEGER,
								stExpressionAccess.codeScp.get( astExp ),
								NULL,NULL );
						stInitDesignationAccess.bIllegal.set( astDesignation, TRUE );
					}
				}
				stInitDesignationAccess.const_expression.set( astDesignation, astExp );
			}
			if( currTokenKind != xLEX_CLOSEARRAY ){
				CcThrowWarning( CC_INITEXP_SYNTAX_ERROR,
						stLexTokenAccess.codeScp.get( astCurrToken ),
						stLexTokenAccess.name.get( astCurrToken ),NULL );
				stInitDesignationAccess.bIllegal.set( astDesignation, TRUE );
			}else{
				astCurrToken = CcLexGetNextToken( );
			}
		}
		secondScp = stLexTokenAccess.codeScp.get( CcLexGetLF(1));
		secondScp = stCoreCodeScpAccess.mergeCodeScp( firstScp, secondScp );
		stInitDesignationAccess.codeScp.set( astDesignation, secondScp );
		if( astPreDesignation == 0 ){
//			astResult = astDesignation;
		}else{
			stInitDesignationAccess.parent.set( astDesignation, astPreDesignation );
			stInitDesignationAccess.child.set( astPreDesignation, astDesignation );
		}
		astPreDesignation = astDesignation;
		astCurrToken = CcLexGetCurrToken( );
		currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );
	}
	if( astDesignation != 0  ){
		if( currTokenKind != xLEX_EQU ){
			CcThrowWarning( CC_INITEXP_SYNTAX_ERROR,
					stLexTokenAccess.codeScp.get( astCurrToken ),
					stLexTokenAccess.name.get( astCurrToken ),NULL );
		}else{
			astCurrToken = CcLexGetNextToken( );
		}
	}
	return astDesignation;
}
static AST ccInitializerList( VOID ){
	AST astInitialList;
	AST  astDesignation;
	AST firstScp, secondScp;
	AST astCurrToken;
	U4  currTokenKind;
	U4  endSym[3] = { xLEX_COMMA, xLEX_CLOSEBLOCK, xLEX_UNDEFINED };

	astCurrToken = CcLexGetCurrToken( );
	firstScp = stLexTokenAccess.codeScp.get( astCurrToken );
	astDesignation = ccInitializerDesignation();

	astCurrToken = CcLexGetCurrToken( );
	currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );
	if( currTokenKind == xLEX_OPENBLOCK ){
		astInitialList = ccInitializerBlock();
	}else{
		astInitialList = ccInitializerAssignExp(endSym);
	}
	stExpressionListAccess.designation.set( astInitialList,astDesignation );
	stInitDesignationAccess.initializer.set(astDesignation ,astInitialList );
	if( stInitDesignationAccess.bIllegal.get( astDesignation ) ){
		stExpressionListAccess.bIllegal.set( astInitialList, TRUE );
	}
	astCurrToken = CcLexGetCurrToken( );
	currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );
	if( currTokenKind != xLEX_COMMA && currTokenKind != xLEX_CLOSEBLOCK ){
		CcThrowWarning( CC_INITEXP_SYNTAX_ERROR,
				stLexTokenAccess.codeScp.get( astCurrToken ),
				stLexTokenAccess.name.get( astCurrToken ),NULL );
	}
	secondScp = stLexTokenAccess.codeScp.get( CcLexGetLF(1) );
	secondScp = stCoreCodeScpAccess.mergeCodeScp( firstScp, secondScp );
	stExpressionListAccess.codeScp.set( astInitialList, secondScp );
	return astInitialList;
}
static AST ccInitializerBlock( VOID ){
	AST astExpList;
	AST astInitial;
	AST astPreInitialList=0;
	AST firstScp, secondScp;
	AST astCurrToken;
	AST astPreToken;
	S2 conflg1,conflg2;
	U4  currTokenKind;

	stExpressionListAccess.alloc(1);
	astInitial = stExpressionListAccess.getMax();

	astCurrToken = CcLexGetCurrToken( );
	firstScp = stLexTokenAccess.codeScp.get( astCurrToken );
	currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );
	if( currTokenKind == xLEX_OPENBLOCK ){
		astCurrToken = CcLexGetNextToken( );
		currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );
	}
	conflg1 = CONSTANT_VALUE;
	while( currTokenKind != xLEX_ENDOFFILE ){
		astPreToken = astCurrToken;
		astExpList = ccInitializerList();

		astCurrToken = CcLexGetCurrToken( );
		firstScp = stLexTokenAccess.codeScp.get( astCurrToken );
		if( astExpList == 0 ){
			CcThrowWarning( CC_INITEXP_SYNTAX_ERROR,
					stLexTokenAccess.codeScp.get( astCurrToken ),
					stLexTokenAccess.name.get( astCurrToken ),NULL );
			stExpressionListAccess.bIllegal.set( astInitial, TRUE );
		}
		if( stExpressionListAccess.bIllegal.get( astExpList ) ){
			stExpressionListAccess.bIllegal.set( astInitial, TRUE );
		}
		conflg2 = stExpressionListAccess.constFlg.get(astExpList);
		if( conflg1 == CONSTANT_VALUE ){
			if( conflg2 != CONSTANT_VALUE ){
				conflg1 = conflg2;
			}
		}else if( conflg1 == INIT_CONSTANT ){
			if( conflg2 != NOT_CONSTANT ){
				conflg1 = conflg2;
			}
		}
		if( astPreInitialList == 0 ){
			stExpressionListAccess.expressionList.set(astInitial,astExpList);
		}else{
			stExpressionListAccess.next.set( astPreInitialList, astExpList );
		}
		stExpressionListAccess.parentKind.set( astExpList, KIND_INITIALEXPLIST );
		stExpressionListAccess.parent.set( astExpList, astInitial );
		astPreInitialList = astExpList;

		astCurrToken = CcLexGetCurrToken( );
		currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );

		if( currTokenKind == xLEX_COMMA ){
			astCurrToken = CcLexGetNextToken( );
			currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );
		}
		if( currTokenKind == xLEX_CLOSEBLOCK || currTokenKind == xLEX_SEMICOLON ){
			break;
		}
		if( astPreToken == astCurrToken ){
			break;
		}
	}
	stExpressionListAccess.constFlg.set(astInitial, conflg1 );
	if( currTokenKind != xLEX_CLOSEBLOCK ){
		CcThrowWarning( CC_INITEXP_SYNTAX_ERROR,
				stLexTokenAccess.codeScp.get( astCurrToken ),
				stLexTokenAccess.name.get( astCurrToken ),NULL );
		secondScp = stLexTokenAccess.codeScp.get( CcLexGetLF(1) );
	}else{
		secondScp = stLexTokenAccess.codeScp.get( astCurrToken );
		astCurrToken = CcLexGetNextToken( );
	}
	secondScp = stCoreCodeScpAccess.mergeCodeScp( firstScp, secondScp );
	stExpressionListAccess.codeScp.set( astInitial, secondScp );
	return astInitial;
}

AST CcInitializerMain( VOID ){
	 U4  usEndSym[3]={ xLEX_COMMA, xLEX_SEMICOLON, xLEX_UNDEFINED } ;
	 AST  astCurrToken;
	 U4   currTokenKind;
	 AST  astResult;

	 astCurrToken = CcLexGetCurrToken() ;
     currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );
     if( currTokenKind == xLEX_OPENBLOCK ){
    	 astResult = ccInitializerBlock();
     }else{
    	 astResult = ccInitializerAssignExp(usEndSym);
     }
	 astCurrToken = CcLexGetCurrToken() ;
     currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );
     if( currTokenKind != xLEX_COMMA && currTokenKind != xLEX_SEMICOLON
    		 && currTokenKind != xLEX_CLOSEPAREN ){
			CcThrowWarning( CC_INITEXP_SYNTAX_ERROR,
					stLexTokenAccess.codeScp.get( astCurrToken ),
					stLexTokenAccess.name.get( astCurrToken ),NULL );
 		while(TRUE)	{
 		    if(    currTokenKind == xLEX_SEMICOLON
 		        || currTokenKind == xLEX_ENDOFFILE
 		        || currTokenKind == xLEX_CLOSEPAREN
 		        || currTokenKind == xLEX_COMMA ){
 		        break ;
 		    }
 		    astCurrToken = CcLexGetNextToken();
 		    currTokenKind = stLexTokenAccess.tokenKind.get( astCurrToken );
 		}
     }
     return astResult;
}
static BOOL ccInitIsConstString( AST astExp ){
	if( stExpressionAccess.opKind.get( astExp ) == EXPR_STRING ){
		return TRUE;
	}
	return FALSE;
}
static BOOL ccInitIsCharArray( AST astType ){
	AST astEleType;
	if( CcTypeIsArray( astType )){
		astEleType = stTypeInfoAccess.elementType.get( astType );
		astEleType = CcTypeGetNoQualType( astEleType );
		if( astEleType == TYPE_CHAR || astEleType == TYPE_UNSIGNED_CHAR || astEleType == TYPE_SIGNED_CHAR  ){
			return TRUE;
		}
	}
	return FALSE;
}
static AST ccInitGetNextObj( AST astObj ){
	AST astNext;
	AST astParent;
	U4  size;
	U4  idx;
	BOOL bAdjustable = FALSE;
	astNext = stObjectMapOfTypeAccess.NextObj.get( astObj );
	if( astNext ){
		return astNext;
	}

	astParent = stObjectMapOfTypeAccess.parent.get( astObj );
	size = stObjectMapOfTypeAccess.size.get( astParent );
	bAdjustable = stObjectMapOfTypeAccess.bAdjustable.get( astParent );
	idx = stObjectMapOfTypeAccess.idx.get( astParent );
	if( bAdjustable == TRUE ){
		/*debug,13/1/25,S*/
		astNext = astObj;
		idx++;
		stObjectMapOfTypeAccess.idx.set( astObj, 0 );
		stObjectMapOfTypeAccess.size.set( astParent, idx);
		//idx++;
		/*debug,13/1/25,E*/
	}else if( idx < size ){
		/*debug,13/1/25,S*/
		astNext = astObj;
		idx++;
		stObjectMapOfTypeAccess.idx.set( astObj, 0 );
		//idx++;
		/*debug,13/1/25,E*/
	}else{
		astNext = 0;
		stObjectMapOfTypeAccess.idx.set( astObj, 0 );
		idx = 0;
	}
	stObjectMapOfTypeAccess.idx.set( astParent, idx );
	return astNext;
}
static AST ccInitGetUnionMemByName( AST astObjMap, PSZ name ){
	AST astSym;
	PSZ pszName;
	AST astChildObj;
	if( str_length( name ) == 0 ){
		return 0;
	}
	astChildObj = stObjectMapOfTypeAccess.child.get( astObjMap );
	while( astChildObj > 0  ){
		astSym = stObjectMapOfTypeAccess.sym.get( astChildObj );
		pszName = stSymbolInfoAccess.name.get( astSym );
		if( strcmp( pszName, name ) == 0 ){
			return astChildObj;
		}
		astChildObj = stObjectMapOfTypeAccess.sameObj.get( astChildObj );
	}
	return 0;
}
static AST ccInitGetStructMemByName( AST astObjMap, PSZ name ){
	AST astSym;
	PSZ pszName;
	AST astChildObj;
	if( str_length( name ) == 0 ){
		return 0;
	}
	astChildObj = stObjectMapOfTypeAccess.child.get( astObjMap );
	while( astChildObj > 0  ){
		astSym = stObjectMapOfTypeAccess.sym.get( astChildObj );
		pszName = stSymbolInfoAccess.name.get( astSym );
		if( strcmp( pszName, name ) == 0 ){
			return astChildObj;
		}
		astChildObj = stObjectMapOfTypeAccess.NextObj.get( astChildObj );
	}
	return 0;
}
static AST  ccInitializeGetTypeByDesignation( AST astObjMap, AST astDesignation  ){
	U2 dekind;
	BOOL bAdjustable = FALSE;
	U4 idx = 0;
	AST astSym;
	PSZ name;
	AST astType;
	AST astTargetObj = 0;
	while( astDesignation ){
		astType = stObjectMapOfTypeAccess.type.get( astObjMap );
		dekind = stInitDesignationAccess.kind.get( astDesignation ) ;
		if( dekind == DESIGNATION_TOKEN || dekind == DESIGNATION_MEMBER ){
			if( dekind == DESIGNATION_TOKEN ){
				name = stLexTokenAccess.name.get(stInitDesignationAccess.token.get( astDesignation ) ) ;
			}else{
				name = stSymbolInfoAccess.name.get(stInitDesignationAccess.identifier.get( astDesignation ) ) ;
			}

			if( CcTypeIsStruct( astType )){
				astTargetObj = ccInitGetStructMemByName( astObjMap, name );
				if( astTargetObj == 0 ){
					CcThrowWarning( CC_INITEXP_DESIGNATION_UNKNOWN_SYM,
							stInitDesignationAccess.codeScp.get( astDesignation ),
							name,NULL );
				}else{
					astSym = stObjectMapOfTypeAccess.sym.get( astTargetObj );
					stInitDesignationAccess.identifier.set(astDesignation, astSym);
				}
			}else if( CcTypeIsUnion( astType ) ){
				astTargetObj = ccInitGetUnionMemByName( astObjMap, name );
				if( astTargetObj == 0 ){
					CcThrowWarning( CC_INITEXP_DESIGNATION_UNKNOWN_SYM,
							stInitDesignationAccess.codeScp.get( astDesignation ),
							name,NULL );
				}else{
					astSym = stObjectMapOfTypeAccess.sym.get( astTargetObj );
					stInitDesignationAccess.identifier.set(astDesignation, astSym);
				}
			}else{
				CcThrowWarning( CC_INITEXP_DESIGNATION_MEM_MISSUSE,
						stInitDesignationAccess.codeScp.get( astDesignation ),
						name,NULL );
				astTargetObj = 0;
			}
		}else if( dekind == DESIGNATION_ARRAY ){
			if( CcTypeIsArray( astType )){
				AST astExp = stInitDesignationAccess.const_expression.get( astDesignation );
				AST astValue = stExpressionAccess.constValue.get( astExp );
				VARVALUE v1;
				if( astValue == 0 ){
					astTargetObj = 0;
				}else{
					v1 = CcValueGetInteger( astValue );
					if( v1.sign < 0 ){
						CcThrowWarning( CC_INITEXP_DESIGNATION_NEED_POSITIVE,
								stInitDesignationAccess.codeScp.get( astDesignation ),
								NULL,NULL );
						astTargetObj = 0;
					}else{
						idx = stObjectMapOfTypeAccess.size.get( astObjMap );
						bAdjustable = stObjectMapOfTypeAccess.bAdjustable.get( astObjMap );
						if ( bAdjustable == TRUE ){
							astTargetObj = stObjectMapOfTypeAccess.child.get( astObjMap );
							stObjectMapOfTypeAccess.idx.set( astObjMap, v1.u8Remainder );
							if( idx < v1.u8Remainder  ){
								stObjectMapOfTypeAccess.size.set( astObjMap, v1.u8Remainder );
							}
						}else if( idx > v1.u8Remainder ){
							astTargetObj = stObjectMapOfTypeAccess.child.get( astObjMap );
							stObjectMapOfTypeAccess.idx.set( astObjMap, v1.u8Remainder );
						}else{
							astTargetObj = 0;
							CcThrowWarning( CC_INITEXP_DESIGNATION_OVERFLOW,
									stInitDesignationAccess.codeScp.get( astDesignation ),
									NULL,NULL );
						}
					}
				}
			}else{
				CcThrowWarning( CC_INITEXP_DESIGNATION_ARRAY_MISSUSE,
						stInitDesignationAccess.codeScp.get( astDesignation ),
						NULL,NULL );
				astTargetObj = 0;
			}
		}
		if( astTargetObj == 0 ){
			break;
		}
		astObjMap = astTargetObj;
		astDesignation = stInitDesignationAccess.child.get( astDesignation ) ;
	}
	return astTargetObj;
}
static VOID ccInitSingleTypeByBlock( AST astType, AST astInitializer ){
	AST astDesignation;
	AST astExpList;
	AST astExp;
	AST astTypeInit;
	BOOL bAssignable;
	U2 paramKind ;

	astExpList = stExpressionListAccess.expressionList.get( astInitializer );
	CcThrowWarning( CC_INITEXP_EXCESS_BRACE,
			stExpressionListAccess.codeScp.get( astInitializer ),
			NULL, NULL  );
	while( astExpList ){
		astDesignation = stExpressionListAccess.designation.get( astExpList );
		if( astDesignation > 0 ){
			if( stInitDesignationAccess.kind.get( astDesignation ) == DESIGNATION_ARRAY ){
				CcThrowWarning( CC_INITEXP_DESIGNATION_ARRAY_MISSUSE,
						stExpressionListAccess.codeScp.get( astInitializer ),
						NULL, NULL  );
			}else{
				CcThrowWarning( CC_INITEXP_DESIGNATION_MEM_MISSUSE,
						stExpressionListAccess.codeScp.get( astInitializer ),
						NULL, NULL  );
			}
		}
		if( stExpressionListAccess.next.get( astExpList ) ){
			CcThrowWarning( CC_INITEXP_EXCESS_ELEMENTS,
					stExpressionListAccess.codeScp.get( astInitializer ),
					NULL, NULL  );
		}
		paramKind = stExpressionListAccess.parameterKind.get( astExpList );
		if( paramKind == KIND_EXPRESSIONINFO ){
			astExp = stExpressionListAccess.expression.get( astExpList );
			astTypeInit = stExpressionAccess.castedType.get( astExp );
			bAssignable = CcTypeIsAssignable(  astTypeInit, astType );
			if( bAssignable == FALSE ){
				CcThrowWarning( CC_INITEXP_UNCOMPATIBABLE_TYPE,
						stExpressionListAccess.codeScp.get( astInitializer ),
						NULL, NULL  );
			}
			/*debug,13/2/8,S*/
			if(stExpressionListAccess.next.get(astExpList)){
				astExpList = stExpressionListAccess.next.get(astExpList);
			}else{
				break;
			}
			/*debug,13/2/8,E*/

		}else{
			CcThrowWarning( CC_INITEXP_EXCESS_BRACE,
					stExpressionListAccess.codeScp.get( astExpList ),
					NULL, NULL  );
			astExpList = stExpressionListAccess.expressionList.get( astExpList );
		}
	}
}
static AST ccInitializerCheckExp( AST astCurrObj, AST astInit ){
	AST astExp;
	AST astTypeInit;
	AST astType;
	AST astChildObj;
	U4 size;
	BOOL bAssignable;

	astExp = stExpressionListAccess.expression.get( astInit );
	astType = stObjectMapOfTypeAccess.type.get( astCurrObj );
	if( ccInitIsCharArray( astType ) && ccInitIsConstString( astExp ) ){
		size = stTypeInfoAccess.size.get( astType );
		if( stObjectMapOfTypeAccess.bAdjustable.get( astCurrObj ) ){
			size = stTypeInfoAccess.size.get( stExpressionAccess.type.get( astExp ));
			stObjectMapOfTypeAccess.size.set( astCurrObj, size );
			stObjectMapOfTypeAccess.bAdjustable.set( astCurrObj, FALSE );
			/* char a[] = "abc";  a size = 4 */
		}else{
			if( size+1 < stTypeInfoAccess.size.get( stExpressionAccess.type.get( astExp ))){
				CcThrowWarning( CC_INITEXP_EXCESS_ELEMENTS,
						stExpressionAccess.codeScp.get( astExp ),
						NULL, NULL  );
				/*
					* char a[2] = "abc";  NG
					* char a[3] = "abc";  OK
					*
					*/
			}
		}
	}else{
		if( EXPR_COMPOUNDLITERALS == stExpressionAccess.opKind.get( astExp ) ){
			astTypeInit = stExpressionAccess.type.get( astExp );
		}else{
			astTypeInit = stExpressionAccess.castedType.get( astExp );
		}
		if( CcTypeIsArray( astTypeInit ) && CcTypeIsArray( astType ) ){
			AST astTempOrg;
			AST astTempDst;
			astTempOrg = stTypeInfoAccess.elementType.get( astTypeInit );
			astTempDst = stTypeInfoAccess.elementType.get( astType );
			bAssignable = CcTypeIsAssignable(  astTempOrg, astTempDst );
			if( bAssignable == FALSE ){
				astChildObj = stObjectMapOfTypeAccess.child.get( astCurrObj );
				if( astChildObj ){
					CcThrowWarning( CC_INITEXP_NEED_BRACE,
							stExpressionAccess.codeScp.get( astExp ),
							NULL, NULL  );
					astCurrObj = ccInitializerCheckExp( astChildObj, astInit );
				}else{
					CcThrowWarning( CC_INITEXP_UNCOMPATIBABLE_TYPE,
							stExpressionAccess.codeScp.get( astExp ),
							NULL, NULL  );
				}
			}else{
				U4 sizeInit = stTypeInfoAccess.size.get( astTypeInit );
				U4 sizeT = stTypeInfoAccess.size.get( astType );
				if( sizeT == 0 ){
					stObjectMapOfTypeAccess.size.set( astCurrObj, sizeInit );
				}else if( sizeT < sizeInit ){
					CcThrowWarning( CC_INITEXP_EXCESS_ELEMENTS,
							stExpressionAccess.codeScp.get( astExp ),
							NULL, NULL  );
				}
			}
		}else{
			bAssignable = CcTypeIsAssignable(  astTypeInit, astType );
			if( bAssignable == FALSE ){
				astChildObj = stObjectMapOfTypeAccess.child.get( astCurrObj );
				if( astChildObj ){
					CcThrowWarning( CC_INITEXP_NEED_BRACE,
							stExpressionAccess.codeScp.get( astExp ),
							NULL, NULL  );
					astCurrObj = ccInitializerCheckExp( astChildObj, astInit );
				}else{
					CcThrowWarning( CC_INITEXP_UNCOMPATIBABLE_TYPE,
							stExpressionAccess.codeScp.get( astExp ),
							NULL, NULL  );
				}
			}
		}
	}
	return astCurrObj;
}
static VOID ccInitializerCheckBlock( AST astObjMap, AST astInit ){
	AST astDesignation;
	AST astType;
	AST astChildObj;
	AST astParent=0;
	AST astCurrObj;
	U2  paramKind;
	BOOL bFixed = FALSE;
	/* when nestLvl = 0 :
	 * char a[] = { 1, 2, 3 };
	 * astType = char[]    astInitializer = { 1, 2, 3 }
	*/

	astChildObj =  stObjectMapOfTypeAccess.child.get( astObjMap );
	if( astChildObj == 0  ){
		astType = stObjectMapOfTypeAccess.type.get( astObjMap );
		ccInitSingleTypeByBlock( astType, astInit );
	}
	astInit = stExpressionListAccess.expressionList.get( astInit );
	astCurrObj = 0;
	while( astInit ){
		bFixed = FALSE;
		astDesignation = stExpressionListAccess.designation.get( astInit );
		if( astDesignation > 0 ){
			astChildObj = ccInitializeGetTypeByDesignation( astObjMap, astDesignation );
			if( astChildObj > 0 ){
				astCurrObj = astChildObj;
				astParent = stObjectMapOfTypeAccess.parent.get( astCurrObj );
			}
			bFixed = TRUE;
		}else{
			if( astCurrObj == 0 ){
				astCurrObj = stObjectMapOfTypeAccess.child.get( astObjMap );
				astParent = astObjMap;
				/*debug,13/1/25,S*/
				stObjectMapOfTypeAccess.idx.set(astParent,1);
				if(stObjectMapOfTypeAccess.size.get(astParent) == 0){
					stObjectMapOfTypeAccess.size.set(astParent,1);
				}
				/*debug,13/1/25,E*/
			}else{
				astCurrObj = ccInitGetNextObj( astCurrObj );
			}
			while( astCurrObj == 0 ){
				astCurrObj = astParent ;
				astParent= stObjectMapOfTypeAccess.parent.get( astCurrObj );
				if( astCurrObj == astObjMap || astCurrObj == 0 ){
					astCurrObj = 0;
					break;
				}
				astCurrObj = ccInitGetNextObj( astCurrObj );
			}
		}
		if( astCurrObj == 0 ){
			break;
		}
		paramKind = stExpressionListAccess.parameterKind.get( astInit );
		if( paramKind == KIND_EXPRESSIONINFO ){
			if( bFixed ){
				ccInitializerCheckExp( astCurrObj, astInit );
			}else{
				astCurrObj = ccInitializerCheckExp( astCurrObj, astInit );
				astParent= stObjectMapOfTypeAccess.parent.get( astCurrObj );
			}
		}else{
			ccInitializerCheckBlock( astCurrObj, astInit );
		}
		astInit = stExpressionListAccess.next.get( astInit );
	}
	if( astInit > 0 && astCurrObj == 0 ){
		CcThrowWarning( CC_INITEXP_EXCESS_ELEMENTS,
				stExpressionListAccess.codeScp.get( astInit ),
				NULL, NULL  );
	}
}
VOID CcInitializerCheck( AST astType, AST astInitializer  ){
	U2  paramKind = stExpressionListAccess.parameterKind.get( astInitializer );
	U4   size;
	AST astDesignation = stExpressionListAccess.designation.get( astInitializer );
	AST astObjMap;

	if( paramKind == KIND_EXPRESSIONINFO  ){
		if( astDesignation != 0 ){
			if( stInitDesignationAccess.kind.get( astDesignation ) == DESIGNATION_ARRAY ){
				CcThrowWarning( CC_INITEXP_DESIGNATION_ARRAY_MISSUSE,
						stExpressionListAccess.codeScp.get( astInitializer ),
						NULL, NULL  );
			}else{
				CcThrowWarning( CC_INITEXP_DESIGNATION_MEM_MISSUSE,
						stExpressionListAccess.codeScp.get( astInitializer ),
						NULL, NULL  );
			}
		}
		astObjMap = CcTypeGetObjMap( astType );
		ccInitializerCheckExp( astObjMap, astInitializer );
	}else{
		astObjMap = CcTypeGetObjMap( astType );
		ccInitializerCheckBlock( astObjMap, astInitializer );
	}
	if( CcTypeIsArray( astType )){
		if( stTypeInfoAccess.bSizeUnDefined.get( astType )
				|| stTypeInfoAccess.bVariableSize.get( astType ) ){
			size = stObjectMapOfTypeAccess.size.get( astObjMap );
			stTypeInfoAccess.size.set( astType, size );
		}
	}
}
VOID CcInitializerWarningNotConstant( AST astInitializer  ){
	U2  paramKind = stExpressionListAccess.parameterKind.get( astInitializer );
	S2  constflg ;
	if( paramKind == KIND_EXPRESSIONINFO  ){

		constflg = stExpressionListAccess.constFlg.get( astInitializer );
		if( NOT_CONSTANT == constflg ){
			CcThrowWarning( CC_INITEXP_NEED_CONSTEXP,
					stExpressionListAccess.codeScp.get( astInitializer ),
					NULL, NULL );
		}
	}else{
		astInitializer = stExpressionListAccess.expressionList.get( astInitializer );
		while( astInitializer ){
			CcInitializerWarningNotConstant( astInitializer );
			astInitializer = stExpressionListAccess.next.get( astInitializer );
		}
	}
}
